package com.lt.bookkeeping.recycleView;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.res.Resources;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lt.bookkeeping.R;
import com.lt.bookkeeping.Utils.Utils;
import com.lt.bookkeeping.dataSave.BookKeepData;

import java.text.MessageFormat;

/**
 * @author LiuTong
 */
public class ItemViewHolder extends BaseHolder<BookKeepData>{
    private TextView tvEvent,tvMoney,tvCreateTime;
    private Resources res;
    public ItemViewHolder(@NonNull View itemView) {
        super(itemView);
        res = context.getResources();
    }

    @Override
    public void initView(View view) {
        tvEvent = itemView.findViewById(R.id.item_data_event);
        tvMoney = itemView.findViewById(R.id.item_data_money);
        tvCreateTime = itemView.findViewById(R.id.item_data_create_time);
    }

    @SuppressLint("StringFormatMatches")
    @Override
    public void onBind(BookKeepData bookKeepData) {
        if(bookKeepData != null){
            tvEvent.setText(String.format(res.getString(R.string.book_event), bookKeepData.getEvent()));
            tvMoney.setText(String.format(res.getString(R.string.book_money), bookKeepData.getMoney()));
            tvCreateTime.setText(String.format(res.getString(R.string.book_money), Utils.getFormData(bookKeepData.getBookKeepTime())));
        }
    }
}
